#!/usr/bin/env python
# !/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2024/8/23 下午7:15
# @Author  : wenrouyue
# @File    : base_page.py
from typing import Optional

from pyrogram import Client

from utils.bot_message import BotMessage


class BasePage:
    def __init__(self, bot_data=None, callback_query=None):
        self.bot_message: Optional[BotMessage] = None
        self.bot_message_by_user: Optional[BotMessage]  = None
        if bot_data:
            self.bot: Optional[Client] = bot_data.get('bot')
            self.chat_id = bot_data.get('chat_id')
            self.user_id = bot_data.get('user_id')
            self.reply_text = bot_data.get('reply_text')
            self.reply_msg_id = bot_data.get('reply_msg_id')
            self.user_name = bot_data.get('user_name')
        if callback_query and hasattr(callback_query, 'message'):
            self.callback_query = callback_query
        elif callback_query:
            self.msg = callback_query

    def set_attributes(self, params):
        if params:
            for key, value in params.items():
                setattr(self, key, value)

    def get_bot_message(self, args=None):
        if args:
            self.bot_message_by_user = BotMessage(self.bot, None, args)
            return self.bot_message_by_user
        else:
            self.bot_message = BotMessage(self.bot,
                                          self.callback_query if hasattr(self, 'callback_query') else getattr(self,
                                                                                                              'msg',
                                                                                                              None))
            return self.bot_message
